package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * &#064;author：zzq
 * &#064;createTime：2025/10/09 10:53
 * &#064;description： 
 */
@RestController
@RequestMapping("/activities")
@Slf4j
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    //查询指定类型的活动请求路径：/activities/type/{type}
    @GetMapping("/type/{type}")
    public Result list(@PathVariable String type) {
        log.info("查询指定类型的活动，参数：{}", type);
        List<Activity> activityList = activityService.listByType(type);
        return Result.success(activityList);
    }
    //修改活动
    @PutMapping
    public Result update(@RequestBody Activity activity) {
        log.info("修改活动信息，参数：{}", activity);
        activityService.update(activity);
        return Result.success();
    }
    //根据id查询活动
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id) {
        log.info("查询活动，参数：{}", id);
        Activity activity = activityService.get(id);
        return Result.success(activity);
    }
    //根据id删除活动
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除活动，参数：{}", id);
        activityService.deleteById(id);
        return Result.success();
    }
    //新增活动
    @PostMapping
    public Result addActivity(@RequestBody Activity activity) {
        log.info("新增活动信息，参数：{}", activity);
        activityService.addActivity(activity);
        return Result.success();
    }

    //活动列表查询
    @GetMapping
    public Result list(ActivityDTO dto) {
        PageResult<Activity> pageResult = activityService.list(dto);
        return Result.success(pageResult);
    }
}
